local textChunks={} for i=1,24 local h=i if h>12 h=h-12 end
if i<=4 table.insert(textChunks,{name="h_"..i,text="Pukul "..h.." dini hari"})
elseif i<=10 table.insert(textChunks,{name="h_"..i,text="Pukul "..h.." pagi"})
elseif i<=14 table.insert(textChunks,{name="h_"..i,text="Pukul "..h.." siang"})
elseif i<=18 table.insert(textChunks,{name="h_"..i,text="Pukul "..h.." sore"})
elseif i<=24 table.insert(textChunks,{name="h_"..i,text="Pukul "..h.." malam"})
end end

require"import" import "android.os.Environment" import "android.speech.tts.TextToSpeech" import "android.speech.tts.UtteranceProgressListener" import "java.io.File" local tts=TextToSpeech(this,function(status) if status==TextToSpeech.ERROR service.asyncSpeak("TextToSpeech Tidak dapat digunakan") elseif status==TextToSpeech.SUCCESS service.asyncSpeak("Berhasil menggunakan TextToSpeech") synthesizetofile() end end) tts.setOnUtteranceProgressListener(UtteranceProgressListener{onStart=function service.playSoundGestureBegin() end,onStop=function service.playSoundGestureEnd() end,onDone=function service.playSoundScroll(1) end,onError=function service.beep() end}) function synthesizetofile() local folderpath=Environment.getExternalStorageDirectory().getAbsolutePath().."/Rekaman TTS/Berbicara jam dan baterai/jam_12" local file=File(folderpath) if not file.exists() file.mkdirs() end for i,v in ipairs(textChunks) local filename=v.name..".wav" local file=File(folderpath,filename) if not file.exists() local params={[TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID]=filename} tts.synthesizeToFile(v.text,params,folderpath.."/"..filename) end end end return true